<?php $this->load->view('qt/header'); ?>


<!--  PAPER WRAP -->
<div class="wrap-fluid">
    <div class="container-fluid paper-wrap bevel tlbr">

        <!-- CONTENT -->
        <!--TITLE -->
        <div class="row">
            <div id="paper-top">
                <div class="col-sm-12">
                    <h2 class="tittle-content-header">
                        <i class="qt-network"></i>
                        <span id="title-header">
                            <?php echo (isset($this->title_header)) ? $this->title_header : 'DANH SÁCH KHÁCH HÀNG';?>
                        </span>
                    </h2>
                </div>
            </div>
        </div>
        <!--/ TITLE -->
        <ul id="breadcrumb">
            <li><span class="entypo-home"></span></li>
            <li><i class="fa fa-lg fa-angle-right"></i></li>
            <li><a href="#main">Trang chủ</a></li>
        </ul>
        <div class="content-wrap"  style="margin-top: 10px;">
      
      <section class="vbox" style="background: white; padding: 5px;">
	<section class="scrollable padder">
		<div class="row">
			<div class="col-md-12">
            <label style="width: 100%; font-size: 16px; font-weight: normal; margin-bottom: 10px;">
            <li class="qt-search" style="float: left; list-style: none; padding:0px 5px;"></li>Tìm theo: </label>
				<form class="form-inline m-b-lg" method="GET" action="<?php echo base_url()?>companies/view/">
					<div class="form-group">
						<input type="text" name="where" placeholder="Tên/Địa chỉ/Số điện thoại" class="form-control" value="<?php echo @$_REQUEST["where"]; ?>">
					</div>

					<div class="form-group">
						<select class="form-control" name="comp_status">
							<option value="">Chọn tình trạng</option>
							<option value="0">Chưa xác nhận</option>
							<option value="1">Đã xác nhận</option>
							<option value="-2">Đang sử lý</option>
						</select>
					</div>
					<div class="form-group">
						<select class="form-control" name="comp_type">   
							<option value="">Chọn loại doanh nghiệp</option>                             
							<option value="1">Công Ty</option>
							<option value="0">Cá Nhân</option>
						</select>
					</div>
					<div class="form-group">
						<button type="submit" class="qtbtn"><li class="qt-search" style="float: left; list-style: none; margin-top: 4px; width: 10px;">&nbsp;</li>Tìm kiếm</button>
					</div>

				</form>

				<section class="panel b-a" style="margin-top: 20px;">
					<div class="panel-heading b-b"> <span style="min-width: 0px !important; background: #ff6700 !important;" class="badge bg-warning pull-right"><?php echo $this->data["count_page"]?></span>  
                    <a href="#" class="font-bold" style="font-size: 14px; font-weight: bold; color: #7d7d7d;">
                    <li class="qt-group2" style="float: left; list-style: none; font-size: 18px;">&nbsp;</li>
                    Danh sách khách hàng</a></div>
					<table style="border: 1px solid #d9d9d9;" class="table table-striped table-condensed table-hover table-bordered table-fixed" id="list_company">
						<thead style="background: #bcbcbc;">
							<tr>
								<th class="qt-tkh"  style="width: 180px"><span class="qt-group"></span>&nbspTên khách hàng</th>
								<th class="qt-tkh" style="width: 170px"><span class="qt-home"></span>&nbspĐịa chỉ</th>
								<th class="qt-tkh col-md-2"><span class="qt-phone"></span>&nbspMã Số Thuế</th>
								<th class="qt-tkh col-md-2"><span class="qt-user"></span>&nbspNgười Quản Lý</th>
								<th class="qt-tkh" style="width: 150px"><span class="qt-loai"></span>&nbspThông tin</th>
								<th class="qt-tkh" style="width: 140px"><span class="qt-thaotac"></span>&nbspTình trạng</th>
							</tr>
						</thead>
						<tbody>
							<?php 
							$per = $this->session->userdata('user_info');
							$my_permisstion = $per["permission_apps"]["AM_SALE_SUPPORT"];			
							

							foreach($this->data["result"] as $num=>$val){
								$n=0;
								$array=array('comp_tax_code','comp_name','comp_address','comp_phone','comp_bank_account','comp_img_verify','comp_img_tax');
								foreach($array as $v){
									if($val[$v]!=""){
										$n+=1;
									}
								}
								
								$color="danger";
								$px=round($n/(count($array))*100);
								if($px>=100){
									$color="success";
								}else if($px>=50){
									$color="warning";
								}

								$result = file_get_contents("http://localhost/ht/hrm/api/search_user_by_app?token=".$this->session->userdata('user_token')."&app_name=AM_SALE_SUPPORT");
								//print_r($result);
								//$array = array("result"=>false,"msg"=>"Không tìm thấy sale quản lý khách hàng này");
								$id = $val["uId"];
								$full_name ="";
								$json = json_decode($result,true);
								if($json["result"]==true){
									foreach($json["users"] as $key =>$va){
										if($va["user_id"]==$id){
											$full_name =$va["user_fullname"];
										}
									}
								}else{
									if($json["result_type"]==0){
										// LOGOUT
										$this->session->sess_destroy();		
										//redirect('/', 'refresh');	
									redirect("http://crm.altamedia.vn", 'refresh');	
									}
								}
								
								$comp_phone =$val["comp_phone"];
								if(isset($my_permisstion["companies"]["hide_comp_phone"])){
								$comp_phone ="********";
								}
								
								$comp_tax_code =$val["comp_phone"];
								$cust_cmnd =$val["cust_cmnd"];
								
								?>
								<tr>
								<td><a href="<?php echo base_url()?>companies/detail?id=<?php echo $val["comp_id"]?>"><?php echo $val["comp_name"]?></a></td>
									<td class="td2"><a href="<?php echo base_url()?>companies/detail?id=<?php echo $val["comp_id"]?>"><?php echo $val["comp_address"]?></a></td>
									<td><a href="<?php echo base_url()?>companies/detail?id=<?php echo $val["comp_id"]?>"><?php echo $cust_cmnd;?></a></td>
									<td><a href="<?php echo base_url()?>companies/detail?id=<?php echo $val["comp_id"]?>"><?php echo $comp_tax_code?></a></td>
									<td>
										

										 <div class="progress m-b-none  active">
										 <div class="progress-bar bg-<?php echo $color?>" data-toggle="tooltip" 
										 data-original-title="<?php echo $px?>%" style="width: <?php 
																 	if($px < 30)
																 		echo 30;else
																 echo $px; ?>%">
										 <span class="per-def"><?php echo $px?>%</span></div>
										 </div>
									</td>
									<td>
									<a href="<?php echo base_url()?>companies/detail?id=<?php echo $val["comp_id"]?>">
										<?php 
										if(isset($_GET['debug'])){
											echo '<span class="label bg-success" style="background: #ff6700 !important;">
												<i data-toggle="tooltip" class="qt-ok config-wrap" style="float: left; color: white; font-size: 14px; padding-right: 20px;"></i>Đã xác nhận</span>';
										}else{
											if($val["comp_status"]==0){
												echo '<span class="label bg-danger" style=" color: black;">
												<i data-toggle="tooltip" class="qt-cam config-wrap" style="float: left; color: black; font-size: 14px; padding-right: 20px;"></i>Chưa xác nhận</span>';
											}else if($val["comp_status"]==-2){
												echo '<span class="label bg-warning" style=" color: black;">
												<i data-toggle="tooltip" class="qt-cam config-wrap" style="float: left; color: black; font-size: 14px; padding-right: 20px;"></i>Đang xử lý</span>';
											}else if($val["comp_status"]==1){
												echo '<span class="label bg-success" style="background: #ff6700 !important;">
												<i data-toggle="tooltip" class="qt-ok config-wrap" style="float: left; color: white; font-size: 14px; padding-right: 20px;"></i>Đã xác nhận</span>';
											}else{
												echo '<span class="label bg-danger" style=" color: black;">
												<i data-toggle="tooltip" class="qt-cam config-wrap" style="float: left; color: black; font-size: 14px; padding-right: 20px;"></i>Chưa xác nhận</span>';
											}
										}

										?>

									</a>
									</td>
								</tr>
								<?php
							}
							?>
							

						</tbody>
						<tfoot>
							<tr>
								<td colspan="6" class="text-center">
									<ul class="pagination qt-pagination">
									<?php 
										$config['base_url'] = base_url().'companies/view';
										$config['total_rows'] = $this->data["count_page"];
										$config['per_page'] = 10; 
										$config['full_tag_open'] = '<li>';
										$config['full_tag_close'] = '</li>';
										$config['last_tag_open'] = '<li>';
										$config['last_tag_close'] = '</li>';
										$config['next_tag_open'] = '<li>';
										$config['next_tag_close'] = '</li>';
										$config['prev_tag_open'] = '<li>';
										$config['prev_tag_close'] = '</li>';
										$config['cur_tag_open'] = '<li><a><b>';
										$config['cur_tag_close'] = '</b></a></li>';
										$config['num_tag_open'] = '<li>';
										$config['num_tag_close'] = '</li>';
										$this->pagination->initialize($config); 
										echo $this->pagination->create_links();
									?>
										
									</ul>
								</td>
							</tr>
						</tfoot>
					</table>
				</section>
			</div>
		</div>
	</section>
</section>


        
</div>
<div class="content-wrap" id="show-content2"></div>
<div class="content-wrap"> 
<?php $this->load->view('qt/footer'); ?>